// import bindMerge from './bind-merge'
import { bindAuth } from '@/api/login'
import { mapGetters } from 'vuex'
import { openKefu } from '@/utils/judge'
export default {
  // components: {
  //   bindMerge
  // },
  data () {
    return {
      bindLoading: false
      // mergeData: {},
      // mergeVisible: false
    }
  },
  computed: {
    ...mapGetters(['appInfo'])
  },
  methods: {
    onBindAuth (params = {}, bindType) {
      return new Promise((resolve, reject) => {
        this.bindLoading = true
        bindAuth(params, { offset: 169 }).then(res => {
          const data = res.data || {}
          this.bindLoading = false
          if (data.need_merge) {
            this.$PsMessageBox({
              iconClass: 'error',
              confirmButtonText: '提交反馈',
              cancelButtonText: '知道啦',
              confirmButtonClass: 'cancel',
              cancelButtonClass: 'el-button--primary',
              message: `该账号已注册登录过，不支持绑定`,
              beforeClose: (action, instance, done) => {
                if (action === 'confirm') {
                  // this.$xz('xz_open_url', kefuUrl[String(this.appInfo.appID)])
                  openKefu()
                } else {
                  done()
                }
              }
            })
            // this.$emit('needMerge', data, bindType)
            // this.mergeData = data
            reject(data)
          } else {
            this.completeBind()
            resolve()
          }
        }).catch(err => {
          this.bindLoading = false
          reject(err)
        })
      })
    },
    /**
     * 绑定完成
     * @param {Boolean} isAgainLogin
     */
    completeBind ({ isAgainLogin } = {}) {
      this.$emit('completeBind')
      if (isAgainLogin) {
        // 需要退出重新登录
        this.$store.dispatch('user/logout')
        // 需重新登录打开登录方式是绑定类型
        this.$store.dispatch('user/login')
        this.$PsMessage({ message: '绑定成功，请重新登录', iconClass: 'success' })
      } else {
        // 更新绑定信息
        this.$store.dispatch('user/getUserInfo')
        this.$PsMessage({ message: '绑定成功', iconClass: 'success' })
      }
    }
  }
}
